#!/usr/bin/perl
# index.cgi
# Logical Volume Management 
require './lvm-lib.pl';
&ReadParse();
my $lv = $in{'lv'};
if(!$lv){
	&error_setup("ERROR");
	&error($text{'err_no_lv'});
}
$lv =~ /dev\/vg\d\/(\S+)/;
#$fstype = get_fstype($lv);
#if($fstype =~ /xfs/){
#	&error_setup("ERROR");
#	&error($text{'err_xfs_snapshot'});
#}
$lvname = $1;
$config{'mkfslock'} = "/var/nas/lock/mkfsd_new";
$config{'rsfslock'} = "/var/nas/lock/resizefsd";
if( -e $config{'mkfslock'}) {
	&redirect("volstat.cgi");
}
elsif(-e $config{'rsfslock'}){
	&redirect("rslvstat.cgi");
}
else{   #-----------No LV Formating--------------#
&header($text{'title_snapshot'}, "", "snapshot", 0, 1, undef, undef, "");

my @pvinfo = &get_pv_info();
my @vginfo = &get_vg_info();
#my @lvinfo = &get_lv_info();
my @snapinfo = &get_snapshot_info();
$nn = @snapinfo;
print "<form name=lvm action=snapshot.cgi method=post onsubmit='return onsubmit_form()'>\n";
print $text{'originlv'};
print "<b>$lvname</b>";
print "<table width=100% class=mode2><tr> <td colpan=6> <hr> </td></tr></table>\n";

#-------------VG infomation-------------#

#print "<table width=100% class=mode2><tr><td colpan=5><hr></td></tr></table>\n";
#-------------LV infomation-------------#
print "<table width=100% class=mode2>\n";
print "<tr><td valign=top><table class=mode1 vorder=0 cellspacing=0 cellpadding=1 width=100%>\n";

print "<tr class=title1><th align=left>$text{'ssvolume'}</th>",
        "<th align=left>$text{'originlv1'}</th>",
        "<th align=left>$text{'sssize'}</th>",
        "<th align=left>$text{'ssusage'}</th>",
        "<th align=left>$text{'ssstatus'}</th>",
        "<th align=left>$text{'ssmntstat'}</th></tr>\n";
$i = 0;
my $usage;
$date = `date`;
$date =~ /CST\s+(\d+)\s*/;
$year = $1;
foreach $sv (@snapinfo) {
    if($sv->{'originlv'} eq $lvname){
        $i++;
        if($i % 2 ==0){
                $dismode = "class=mode2";
        }else{
                $dismode = "class=mode1";
        }
	$time = `ls -l $sv->{'svdev'}`;
	$time =~
        print "<tr $dismode><td nowarp $dismode width=30%>";
	print "<input type=radio name=sv value=$sv->{'sv'} $disable onclick='SetLvValue(\"$sv->{'status_m'}\", \"$sv->{'svpath'}\")'>";	
	print "$sv->{'svname'}</td>\n";
        print "<td>$sv->{'originlv'}</td>\n";
        print "<td>$sv->{'size'}M</td>\n";
        print "<td>$sv->{'usage'}%</td>\n";
       	print "<td>$sv->{'status_a'}</td>\n";
	#print "<td>$sv->{'status_m'}</td>\n";
	if($sv->{'status_m'}){
		print "<td>$text{'ssmounted'}</td>\n";
	}
	else{
		print "<td>$text{'ssunmounted'}</td>\n";
	}
        print "</tr>\n";
	
    }
}
print "</table></td>";

print "<td valign=top width=60>";
print "<table class=mode1 border=0 cellspacing=8 cellpadding=1 width=6>\n";
#print "<tr><td><input type=hidden name=lvinfo value=$text{'bt_lv_info'} class=button onclick='return SetEditValue_lv(this, $i)'></td></tr>";
#print "<tr><td><input type=submit name=lvformat value=$text{'bt_lv_format'} class=button onclick='return SetEditValue_lv(this, $i)' disabled=true></td></tr>";
#print "<tr><td><input type=submit name=iscsi value=iSCSI class=button onclick='return SetEditValue_lv(this, $i)' disabled=true></td></tr>\n";
print "<tr><td><input type=submit name=sscreate value=$text{'bt_createss'} class=button onclick='return SetEditValue_ss(this, $i)'></td></tr>";
print "<tr><td><input type=submit name=snapshot value=$text{'bt_sv_conn'} class=button onclick='return SetEditValue_ss(this, $i)'></td></tr>\n";
print "<tr><td><input type=submit name=snapshare value=$text{'svshare'} class=button onclick='return SetEditValue_ss(this, $i)'></td></tr>\n";
print "<tr><td><input type=submit name=ssdelete value=$text{'bt_deletess'} class=button onclick='return SetEditValue_ss(this, $i)'></td></tr>";
#print "<tr><td><input type=submit name= value= class=button></td></tr>";
print "</table></td></tr></table>\n";
print "<input type=hidden name=lv value=$lv>\n";
$path = "/snapshot/v2snapshot1";
print "<input type=hidden name=sharepath>\n";
print "<input type=hidden name=edit value=property>";
print "<input type=hidden name=src value=disk>";
#print "<input type=hidden name=cat value=x>";
############################################################
#print "<input type=hidden name=abc>";
print <<EOF;
<script>

function onsubmit_form()
{
//	alert('abc');
}

function GetSelect_ss(obj,n)
{
	var j;
	var findlv = false;
	if (n > 1) {
		for (j = 0; j < document.lvm.sv.length; j++) {
			if (document.lvm.sv[j].checked) {
				findlv = true;
				break;
			}
		}
	}
	else if (n == 1) {
		if (document.lvm.sv.checked) {
			findlv = true;
		}
	}
	return findlv;
}

function SetEditValue_ss(obj,n)
{
	if(GetSelect_ss(obj,n)){
                if(obj == document.lvm.ssdelete) {
                        if(!confirm("$text{'deletelvconfirm'}"))
                                return false;
                }
	}
	else{
		if(!(obj == document.lvm.sscreate)) {
			alert("$text{'err_noselectlv'}");
			return false;
		}
	} 
	if (obj == document.lvm.sscreate) {
		document.lvm.action = 'sscreate.cgi';
	}
	else if (obj == document.lvm.ssdelete) {
		document.lvm.action = 'ssdelete.cgi';
	}
	else if (obj == document.lvm.snapshot) {
		document.lvm.action = 'connsnapshot.cgi';
	}
        else if (obj == document.lvm.snapshare) {
                document.lvm.action = '../shareman/edit_share.cgi';
        }	
}
function SetLvValue(n,m)
{
	document.lvm.sharepath.value = m;
	if (n==0) {
		document.lvm.snapshare.disabled = true;
		//document.lvm.snapshot.disabled = true;	
	}
	else {
		document.lvm.snapshare.disabled = false;
		document.lvm.snapshot.disabled = false;
	}
}
</script>

EOF

print "</form>";
&footer("index.cgi", $text{'index'});

} #no lv formating...
